#include "page_manager.h"

#include <stdio.h>
#include "epd.h"

uint8_t pic_id = 0;
uint8_t pic_update_flag = 0;

static void Setup(uint8_t condition)
{

    Paint_Clear(WHITE);
    SSD1677_DispString_EN_CH(0,0, BLACK, 32, SongTi, 0, "\xC8\xCB\xD7\xEE\xB1\xA6\xB9\xF3\xB5\xC4\xCA\xC7\xC9\xFA\xC3\xFC\xA1\xA3" );
    SSD1677_DispString_EN_CH(0,32, BLACK, 32, SongTi, 0, "\xC9\xFA\xC3\xFC\xC3\xBF\xB8\xF6\xC8\xCB\xD6\xBB\xD3\xD0\xD2\xBB\xB4\xCE\xA1\xA3" );
    SSD1677_DispString_EN_CH(0,32*2, BLACK, 32, SongTi, 0, "\xC8\xCB\xB5\xC4\xD2\xBB\xC9\xFA\xD3\xA6\xB5\xB1\xD5\xE2\xD1\xF9\xB6\xC8\xB9\xFD\xA3\xBA" );
    SSD1677_DispString_EN_CH(0,32*3, BLACK, 32, SongTi, 0, "\xB5\xB1\xBB\xD8\xD2\xE4\xCD\xF9\xCA\xC2\xB5\xC4\xCA\xB1\xBA\xF2\xA3\xAC" );
    SSD1677_DispString_EN_CH(0,32*4, BLACK, 32, SongTi, 0, "\xCB\xFB\xB2\xBB\xBB\xE1\xD2\xF2\xCE\xAA\xD0\xE9\xB6\xC8\xC4\xEA\xBB\xAA\xB6\xF8\xBB\xDA\xBA\xDE\xA3\xAC" );
    SSD1677_DispString_EN_CH(0,32*5, BLACK, 32, SongTi, 0, "\xD2\xB2\xB2\xBB\xBB\xE1\xD2\xF2\xCE\xAA\xC2\xB5\xC2\xB5\xCE\xDE\xCE\xAA\xB6\xF8\xD0\xDF\xC0\xA2\xA3\xBB" );
    SSD1677_DispString_EN_CH(0,32*6, BLACK, 32, SongTi, 0, "\xD4\xDA\xC1\xD9\xCB\xC0\xB5\xC4\xCA\xB1\xBA\xF2\xA3\xAC" );
    SSD1677_DispString_EN_CH(0,32*7, BLACK, 32, SongTi, 0, "\xCB\xFB\xC4\xDC\xB9\xBB\xCB\xB5\xA3\xBA\xA1\xAE\xCE\xD2\xB5\xC4\xD5\xFB\xB8\xF6\xC9\xFA\xC3\xFC\xBA\xCD\xC8\xAB\xB2\xBF\xBE\xAB\xC1\xA6\xA3\xAC" );
    SSD1677_DispString_EN_CH(0,32*8, BLACK, 32, SongTi, 0, "\xB6\xBC\xD2\xD1\xBE\xAD\xCF\xD7\xB8\xF8\xC1\xCB\xCA\xC0\xBD\xE7\xC9\xCF\xD7\xEE\xD7\xB3\xC0\xF6\xB5\xC4\xCA\xC2\xD2\xB5" );
    SSD1677_DispString_EN_CH(0,32*9, BLACK, 32, SongTi, 0, "\x2D\x2D\xCE\xAA\xC8\xCB\xC0\xE0\xB5\xC4\xBD\xE2\xB7\xC5\xB6\xF8\xB6\xB7\xD5\xF9\xA1\xA3" );
    EPD_Paint_Update();

} 


static void Loop(void)
{

    if(pic_update_flag)
    {
        pic_update_flag = 0;
        if(pic_id == 0)
        {
            Paint_Clear(WHITE);
            SSD1677_DispString_EN_CH(0,0, BLACK, 32, SongTi, 0, "\xC8\xCB\xD7\xEE\xB1\xA6\xB9\xF3\xB5\xC4\xCA\xC7\xC9\xFA\xC3\xFC\xA1\xA3" );
            SSD1677_DispString_EN_CH(0,32, BLACK, 32, SongTi, 0, "\xC9\xFA\xC3\xFC\xC3\xBF\xB8\xF6\xC8\xCB\xD6\xBB\xD3\xD0\xD2\xBB\xB4\xCE\xA1\xA3" );
            SSD1677_DispString_EN_CH(0,32*2, BLACK, 32, SongTi, 0, "\xC8\xCB\xB5\xC4\xD2\xBB\xC9\xFA\xD3\xA6\xB5\xB1\xD5\xE2\xD1\xF9\xB6\xC8\xB9\xFD\xA3\xBA" );
            SSD1677_DispString_EN_CH(0,32*3, BLACK, 32, SongTi, 0, "\xB5\xB1\xBB\xD8\xD2\xE4\xCD\xF9\xCA\xC2\xB5\xC4\xCA\xB1\xBA\xF2\xA3\xAC" );
            SSD1677_DispString_EN_CH(0,32*4, BLACK, 32, SongTi, 0, "\xCB\xFB\xB2\xBB\xBB\xE1\xD2\xF2\xCE\xAA\xD0\xE9\xB6\xC8\xC4\xEA\xBB\xAA\xB6\xF8\xBB\xDA\xBA\xDE\xA3\xAC" );
            SSD1677_DispString_EN_CH(0,32*5, BLACK, 32, SongTi, 0, "\xD2\xB2\xB2\xBB\xBB\xE1\xD2\xF2\xCE\xAA\xC2\xB5\xC2\xB5\xCE\xDE\xCE\xAA\xB6\xF8\xD0\xDF\xC0\xA2\xA3\xBB" );
            SSD1677_DispString_EN_CH(0,32*6, BLACK, 32, SongTi, 0, "\xD4\xDA\xC1\xD9\xCB\xC0\xB5\xC4\xCA\xB1\xBA\xF2\xA3\xAC" );
            SSD1677_DispString_EN_CH(0,32*7, BLACK, 32, SongTi, 0, "\xCB\xFB\xC4\xDC\xB9\xBB\xCB\xB5\xA3\xBA\xA1\xAE\xCE\xD2\xB5\xC4\xD5\xFB\xB8\xF6\xC9\xFA\xC3\xFC\xBA\xCD\xC8\xAB\xB2\xBF\xBE\xAB\xC1\xA6\xA3\xAC" );
            SSD1677_DispString_EN_CH(0,32*8, BLACK, 32, SongTi, 0, "\xB6\xBC\xD2\xD1\xBE\xAD\xCF\xD7\xB8\xF8\xC1\xCB\xCA\xC0\xBD\xE7\xC9\xCF\xD7\xEE\xD7\xB3\xC0\xF6\xB5\xC4\xCA\xC2\xD2\xB5" );
            SSD1677_DispString_EN_CH(0,32*9, BLACK, 32, SongTi, 0, "\x2D\x2D\xCE\xAA\xC8\xCB\xC0\xE0\xB5\xC4\xBD\xE2\xB7\xC5\xB6\xF8\xB6\xB7\xD5\xF9\xA1\xA3" );
            EPD_Paint_Update_A2();
        }
        else if(pic_id == 1)
        {
            epd_1gray_display_all(gImage_1, EPD_REF_MODE_A2);   
        }
        else if(pic_id == 2)
        {
            epd_1gray_display_all(gImage_2, EPD_REF_MODE_A2);
        }
        else if(pic_id == 3)
        {
            Paint_Clear(WHITE);
            Paint_DrawRectangle(1,1,480,800,BLACK,DRAW_FILL_EMPTY,DOT_PIXEL_1X1);
            Paint_DrawRectangle(100,100,200,200,BLACK,DRAW_FILL_FULL,DOT_PIXEL_1X1);
            Paint_DrawCircle(200,600,100,BLACK,DRAW_FILL_EMPTY,DOT_PIXEL_1X1);
            Paint_DrawString_EN(150,400, "hello world!", &Font24, WHITE, BLACK);
            SSD1677_DispString_EN_CH(150,500, BLACK, 32, SongTi, 0, "\xC4\xE3\xBA\xC3\xCA\xC0\xBD\xE7" );
            EPD_Paint_Update_A2();
       
        }
        
    }


} 

static void Exit(uint8_t condition)
{
	printf("page_menu Exit\n");
}

static void Event(uint8_t event)
{
    if(event == 4)
    {
		page_manager_switch_page(page_id_menu, PAGE_CONDITION_ENTER);
    }
    else if(event == 2)
    {
        pic_id++;
        if(pic_id > 3)
            pic_id = 0;
        pic_update_flag = 1;
    }
    else if(event == 3)
    {
        if(pic_id == 0)
        {
            pic_id = 1;
        }
        else
        {
            pic_id--;
        }
        pic_update_flag = 1;
    }


}








// 注册页面
void page_register_page_id_read(uint8_t page_id)
{
	page_register(page_id, NULL, NULL, Setup, Loop, Exit, Event);
}










